﻿using System;
using System.ComponentModel;
using System.Data;
using System.Windows;
using System.Windows.Input;
using System.Windows.Controls;
using ReflectionStudio.Core.Events;
namespace WPFExcelReport
{
    public partial class UIABF : ViewBase
    {
        public VABFOLGE TMV
        {
            get
            {
                return (VABFOLGE)MV;
            } 
        }

        #region ==REWEIL===========
        public static readonly DependencyProperty REWEILProperty = DependencyProperty.Register("REWEIL",
            typeof(string), typeof(UIABF),
            new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnREWEILChanged));
        public string REWEIL
        {
            get
            {
                return (string)GetValue(REWEILProperty);
            }
            set
            {
                SetValue(REWEILProperty, value);
            }
        }
        private static void OnREWEILChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIABF;
            if (src != null)
            {
                src.REWEIL = (string)e.NewValue;
            }
        }
        #endregion
        #region ==VU1===========
        public static readonly DependencyProperty VU1Property = DependencyProperty.Register("VU1",
            typeof(string), typeof(UIABF),
            new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnVU1Changed));
        public string VU1
        {
            get
            {
                return (string)GetValue(VU1Property);
            }
            set
            {
                SetValue(VU1Property, value);
                OnVU1Chg(value);
            }
        }
        private static void OnVU1Changed(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIABF;
            if (src != null)
            {
                src.VU1 = (string)e.NewValue;
            }
        }
        public virtual void OnVU1Chg(string value)
        { }
        #endregion

        #region ==FTAUTOSPLIT===========
        public static readonly DependencyProperty FTAUTOSPLITProperty = DependencyProperty.Register("FTAUTOSPLIT",
            typeof(bool), typeof(UIABF),
            new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnFTAUTOSPLITChanged));
        public bool FTAUTOSPLIT
        {
            get
            {
                return (bool)GetValue(FTAUTOSPLITProperty);
            }
            set
            {
                SetValue(FTAUTOSPLITProperty, value);
            }
        }
        private static void OnFTAUTOSPLITChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIABF;
            if (src != null)
            {
                src.FTAUTOSPLIT = (bool)e.NewValue;
            }
        }
        #endregion

        #region ==AGANG===========
        public static readonly DependencyProperty AGANGProperty = DependencyProperty.Register("AGANG",
            typeof(string), typeof(UIABF),
            new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnAGANGChanged));
        public string AGANG
        {
            get
            {
                return (string)GetValue(AGANGProperty);
            }
            set
            {
                SetValue(AGANGProperty, value);
                ((VABFOLGE)MV).AGANG = value;
            }
        }
        private static void OnAGANGChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIABF;
            if (src != null)
            {
                src.AGANG = (string)e.NewValue;
            }
        }
        #endregion

        #region ==RPAUF===========
        public static readonly DependencyProperty RPAUFProperty = DependencyProperty.Register("RPAUF",
            typeof(string), typeof(UIABF),
            new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnRPAUFChanged));
        public string RPAUF
        {
            get
            {
                return (string)GetValue(RPAUFProperty);
            }
            set
            {
                SetValue(RPAUFProperty, value); 
            }
        }
        private static void OnRPAUFChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIABF;
            if (src != null)
            {
                src.RPAUF = (string)e.NewValue;
            }
        }
        #endregion

        #region ==KSTKRS===========
        public static readonly DependencyProperty KSTKRSProperty = DependencyProperty.Register("KSTKRS",
            typeof(string), typeof(UIABF),
            new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnKSTKRSChanged));
        public string KSTKRS
        {
            get
            {
                return (string)GetValue(KSTKRSProperty);
            }
            set
            {
                SetValue(KSTKRSProperty, value);
            }
        }
        private static void OnKSTKRSChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIABF;
            if (src != null)
            {
                src.KSTKRS = (string)e.NewValue;
            }
        }
        #endregion

        #region ==MACHINE===========
        public static readonly DependencyProperty MACHINEProperty = DependencyProperty.Register("MACHINE",
            typeof(string), typeof(UIABF),
            new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnMACHINEChanged));
        public string MACHINE
        {
            get
            {
                return (string)GetValue(MACHINEProperty);
            }
            set
            {
                SetValue(MACHINEProperty, value);
                OnMACHINEChg(value);
            }
        }
        private static void OnMACHINEChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIABF;
            if (src != null)
            {
                src.MACHINE = (string)e.NewValue;
            }
        }
        public virtual void OnMACHINEChg(string am)
        { }
        #endregion



        #region ==KST===========
        public static readonly DependencyProperty KSTProperty = DependencyProperty.Register("KST",
            typeof(string), typeof(UIABF),
            new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnKSTChanged));
        public string KST
        {
            get
            {
                return (string)GetValue(KSTProperty);
            }
            set
            {
                SetValue(KSTProperty, value);
            }
        }
        private static void OnKSTChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIABF;
            if (src != null)
            {
                src.KST = (string)e.NewValue;
            }
        }
        #endregion

        #region ==MTYP===========
        public static readonly DependencyProperty MTYPProperty = DependencyProperty.Register("MTYP",
            typeof(string), typeof(UIABF),
            new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnMTYPChanged));
        public string MTYP
        {
            get
            {
                return (string)GetValue(MTYPProperty);
            }
            set
            {
                SetValue(MTYPProperty, value);
            }
        }
        private static void OnMTYPChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIABF;
            if (src != null)
            {
                src.MTYP = (string)e.NewValue;
            }
        }
        #endregion

        #region ==dwABF===========
        public static readonly DependencyProperty dwABFProperty = DependencyProperty.Register("dwABF",
            typeof(DataRow), typeof(UIABF),
            new FrameworkPropertyMetadata(null, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OdwABFChanged));
        public DataRow dwABF
        {
            get
            {
                return (DataRow)GetValue(dwABFProperty);
            }
            set
            {
                SetValue(dwABFProperty, value); 
            }
        }
        private static void OdwABFChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIABF;
            if (src != null)
            {
                DataRow row = (DataRow)e.NewValue;
                src.dwABF = row;
            }

        }
        #endregion

        #region ==dwNAPF===========
        public static readonly DependencyProperty dwNAPFProperty = DependencyProperty.Register("dwNAPF",
            typeof(DataRow), typeof(UIABF),
            new FrameworkPropertyMetadata(null, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OdwNAPFChanged));
        public DataRow dwNAPF
        {
            get
            {
                return (DataRow)GetValue(dwNAPFProperty);
            }
            set
            {
                SetValue(dwNAPFProperty, value); 
            }
        }
        private static void OdwNAPFChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIABF;
            if (src != null)
            {
                DataRow row = (DataRow)e.NewValue;
                src.dwNAPF = row;
            }

        }
        #endregion

        #region ==dwABP===========
        public static readonly DependencyProperty dwABPProperty = DependencyProperty.Register("dwABP",
            typeof(DataRow), typeof(UIABF),
            new FrameworkPropertyMetadata(null, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OndwABPChanged));
        public DataRow dwABP
        {
            get
            {
                return (DataRow)GetValue(dwABPProperty);
            }
            set
            {
                SetValue(dwABPProperty, value); 
            }
        }
        private static void OndwABPChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIABF;
            if (src != null)
            {
                src.dwABP = (DataRow)e.NewValue;
            }
        }
        #endregion

        #region ==ABFMASCHZE===========
        public static readonly DependencyProperty ABFMASCHANZProperty = DependencyProperty.Register("ABFMASCHZE",
            typeof(string), typeof(UIABF),
            new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnABFMASCHANZChanged));
        public string ABFMASCHZE
        {
            get
            {
                return (string)GetValue(ABFMASCHANZProperty);
            }
            set
            {
                SetValue(ABFMASCHANZProperty, value);
                OnABFMASCHANZChg();
            }
        }
        private static void OnABFMASCHANZChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIABF;
            if (src != null)
            {
                src.ABFMASCHZE = (string)e.NewValue;
            }
        }
        public virtual void OnABFMASCHANZChg()
        {
            if (!IsEdit)
                return;
            if (dwMaster == null)
                return;
            TMV.ABFMASCHZE = ABFMASCHZE;
        }
        #endregion

        #region ==ABFME===========
        public static readonly DependencyProperty ABFMEProperty = DependencyProperty.Register("ABFME",
            typeof(string), typeof(UIABF),
            new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnABFMEChanged));
        public string ABFME
        {
            get
            {
                return (string)GetValue(ABFMEProperty);
            }
            set
            {
                SetValue(ABFMEProperty, value);
              
            }
        }
        private static void OnABFMEChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIABF;
            if (src != null)
            {
                src.ABFME = (string)e.NewValue;
                src.OnABFMEChg();
            }
        }
        public virtual void OnABFMEChg()
        {
            if (!IsEdit)
                return;
            if (dwMaster == null)
                return;
            TMV.ABFME = ABFME;
        }
        #endregion

        public UIABF()
        { 
             
        }

        public override void Window_Loaded(object sender, RoutedEventArgs e)
        {
            if (DesignerProperties.GetIsInDesignMode(this))
                return;
            if (IsLoaded)
                return;
            base.Window_Loaded(sender, e);
        }
       
        public override void vwMaster_CurrentChanged(object sender, EventArgs e)
        {
            base.vwMaster_CurrentChanged(sender, e);
            dwABF = dwMaster;
            if (dwMaster == null)
            {
                KEY = "";
               
            }
            else
            {
                KEY = TMV.ABFAUFKRS+ TMV.ABFAUFLFD+ TMV.ABFAUFPOS+ TMV.ABFAFOLGE;
               
            } 
        }
        
    }
}
